﻿using Project.API.Models;
using Project.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Project.API.Controllers
{
    public class DDorderController : ApiController
    {
        // GET: api/DDorder
        [Route("Api/DDorder")]
        public ResultData<List<DDorderDto>> Get()
        {
            int count = 0;
            var list = new DDorderBll().Query();

            var data = from r in list
                       select new DDorderDto
                       {
                           Ddid = r.Ddid,
                           Type = r.Type,
                           DDsum = r.DDsum,
                           twoYmonth = r.twoYmonth,
                           gtid = r.GoodsType.gtId,
                           name = r.GoodsType.name
                       };


            ResultData<List<DDorderDto>> result = new ResultData<List<DDorderDto>>();
            result.code = 0;
            result.msg = "ok";
            result.data = data.ToList();

            return result;
        }

        [Route("Api/DDorderPage")]
        public ResultPageList<DDorderDto> Get(int page, int limit)
        {
            int count = 0;
            var list = new DDorderBll().GetDDorderByPage(page, limit, out count);

            var data = from r in list
                       select new DDorderDto
                       {
                           Ddid = r.Ddid,
                           Type = r.Type,
                           DDsum = r.DDsum,
                           twoYmonth = r.twoYmonth,
                           gtid = r.GoodsType.gtId,
                           name = r.GoodsType.name
                       };

            ResultPageList<DDorderDto> result = new ResultPageList<DDorderDto>();
            result.code = 0;
            result.msg = "ok";
            result.count = count;
            result.data = data.ToList();

            return result;
        }

        // GET: api/DDorder/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/DDorder
        public void Post([FromBody]string value)
        {
        }

        // PUT: api/DDorder/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE: api/DDorder/5
        public void Delete(int id)
        {
        }
    }
}
